<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>绘制行政区划边界</title>
    <script type="text/javascript" src="http://webapi.amap.com/maps?v=1.3&key=33362fa30e2c1c2ebea500f541fa0df5"></script>
	<link rel="stylesheet" type="text/css" href="../css/styles.css" media="all" />
    <link rel="stylesheet" type="text/css" href="../css/demo.css" media="all" />
</head>
<body>
<div id="container" style="width: 1000px; height: 700px;"></div>
<script type="text/javascript">
    //初始化地图对象，加载地图
    var district, map = new AMap.Map("container");
     var lnglats=[
         [118.391734,31.369373],//鸠江区
         [118.433068,31.352632],//芜湖市
         [118.385146,31.340404],//镜湖区
         [118.268101,31.219568],//三山区
         [118.576124,31.134809],//芜湖县
         [117.902366,31.303168],//无为县
         [118.33436,30.914923],//南陵县
         [118.372655,31.311757],//弋江区
         [118.365166,31.416172],//经开区
         [118.201349,31.080896],//繁昌县
         [118.250832,31.474566],//江北集中区
     ];
     var area=['鸠江区','芜湖市','镜湖区','三山区','芜湖县','无为县','南陵县','弋江区','经开区',
     '繁昌县','江北集中区'];
    var infoWindow = new AMap.InfoWindow({offset:new AMap.Pixel(0,-30)});
     for(var i= 0,marker;i<lnglats.length;i++){
          var marker=new AMap.Marker({
              position:lnglats[i],
              map:map,
             icon: new AMap.Icon({            
            	size: new AMap.Size(18, 16),  //图标大小
            	image: "../img/bar.png"
        		})        
          });
        marker.content=area[i];
        marker.on('click',markerClick);
        //marker.emit('click',{target:marker});
    }
     function markerClick(e){
     	var str="<div id=\"fdw-pricing-table\"><div class=\"plan plan1\">"
     	+"<div class=\"header\">"+e.target.content+"</div>"
     	+"<ul><li>实有人口 50万</li></ul>"
        infoWindow.setContent(str);
        infoWindow.open(map, e.target.getPosition());
    }
    map.setMapStyle("dark");
    map.setFitView();
    addWuhu();
    function addWuhu() {
        //加载行政区划插件
        AMap.service('AMap.DistrictSearch', function() {
            var opts = {
                subdistrict: 1,   //返回下一级行政区
                extensions: 'all',  //返回行政区边界坐标组等具体信息
                level: 'city'  //查询行政级别为 市
            };
            //实例化DistrictSearch
            district = new AMap.DistrictSearch(opts);
            district.setLevel('district');
            //行政区查询
            district.search('芜湖市', function(status, result) {
                var bounds = result.districtList[0].boundaries;
                var polygons = [];
                if (bounds) {
                    for (var i = 0, l = bounds.length; i < l; i++) {
                        //生成行政区划polygon
                        var polygon = new AMap.Polygon({
                            map: map,
                            strokeWeight: 2,
                            path: bounds[i],
                            fillOpacity: 0.1,
                            fillColor: '#fff',
                            strokeColor: '#000080'
                        });
                        polygons.push(polygon);
                    }
                    map.setFitView();//地图自适应
                }
            });
        });
    }
</script>

</body>
</html>
